<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>实验室助理管理系统</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/login.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <script>if (window.top !== window.self) {
        window.top.location = window.location;
    }</script>
</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen   animated fadeInDown">
    <div>
        <div>

            <h1 class="logo-name">H+</h1>

        </div>
        <h3>欢迎注册 实验室助理管理系统账户</h3>
        <p>创建一个新账户</p>
        <form class="m-t">
            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入学号" id="studentNo" name="studentNo" required="">
            </div>
            <div class="form-group">
                <input type="password" class="form-control" placeholder="请输入密码" id="studentPwd" name="studentPwd" required=""
                >
            </div>
            <div class="form-group">
                <input type="password" class="form-control" placeholder="请再次输入密码" id="L_repass" name="repass" required=""
                >
            </div>
            <div class="form-group">
                <input type="file" id="file" name="file" autocomplete="off">
            </div>
            <input type="hidden" id="imgUrl" name="imgUrl" value="" lay-verify="imgUrl">
            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入姓名" id="studentName" name="studentName" required=""
                >
            </div>
            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入学院" id="studentMajor" name="studentMajor" required=""
                >
            </div>
            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入年级" id="studentCollege" name="studentCollege" required=""
                >
            </div>
            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入专业" id="studentGrade" name="studentGrade" required=""
                >
            </div>
            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入手机号" id="studentMobile" name="studentMobile" required=""
                >
            </div>
            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入邮箱" id="studentEmail" name="studentEmail" required=""
                >
            </div>
            <button type="button" onclick="register()" class="btn btn-primary block full-width m-b">注 册</button>

            <p class="text-muted text-center"><small>已经有账户了？</small><a th:href="@{/}">点此登录</a>
            </p>

        </form>
    </div>
</div>

<!-- 全局js -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>

<script>
    function register() {

        var studentNo = $('#studentNo').val();
        var studentPwd = $('#studentPwd').val();
        var repass = $('#L_repass').val();
        var imgUrl = $('#imgUrl').val();
        var studentName = $('#studentName').val();
        var studentMajor = $('#studentMajor').val();
        var studentCollege = $('#studentCollege').val();
        var studentGrade = $('#studentGrade').val();
        var studentMobile = $('#studentMobile').val();
        var studentEmail= $('#studentEmail').val();

        if (studentPwd != repass) {
            alert("输入的两次密码不相同！");
            return false;
        } else if (studentNo == null && studentNo == "") {
            alert("学号不能为空！")
        } else if (studentPwd == null && studentPwd == "") {
            alert("密码不能为空！")
        } else if (repass == null && repass == "") {
            alert("再次输入密码不能为空！")
        } else if (imgUrl == null && imgUrl == "") {
            alert("个人相片不能为空！")
        } else if (studentName == null && studentName == "") {
            alert("学生姓名不能为空！")
        } else if (studentMajor == null && studentMajor == "") {
            alert("专业不能为空！")
        } else if (studentCollege == null && studentCollege == "") {
            alert("学院不能为空！")
        } else if (studentGrade == null && studentGrade == "") {
            alert("年级不能为空！")
        } else if (studentMobile == null && studentMobile == "") {
            alert("电话不能为空！")
        } else if (studentEmail == null && studentEmail == "") {
            alert("邮箱不能为空！")
        } else {
            $.ajax({
                type: "post",
                url: "http://localhost:9527/sysLab/student/studentAdd",
                async: false,
                dataType: 'json',
                data: {
                    studentNo: studentNo,
                    studentPwd: studentPwd,
                    studentName: studentName,
                    imgUrl: imgUrl,
                    studentMajor: studentMajor,
                    studentCollege: studentCollege,
                    studentGrade: studentGrade,
                    studentMobile: studentMobile,
                    studentEmail: studentEmail
                },
                success: function (res) {
                    if (res.data == "success") {
                        alert("注册成功！");
                        location.href = "http://localhost:9527/sysLab/";
                    } else {
                        alert(res.msg);
                    }
                },
                error: function () {
                    alert("未填写合法的信息！");
                }
            })

        }

   }

</script>


<script>
    document.getElementById("file").addEventListener("change", function () {
        //console.log("change==>");
        /**
         * 图片上传 formdata进行数据传输！
         * @type {jQuery|HTMLElement}
         */
        $ = layui.jquery;

        var url = $('#file')[0].files[0];
        //console.log("==>"+url)
        var form = new FormData();
        form.set('file', url);

        $.ajax({
            type: "post",
            url: "http://localhost:9527/sysLab/student/fileUpload",
            async: false,
            dataType: 'json',
            processData: false,
            contentType: false,
            data: form,
            success: function (res) {
                //console.log("res==>"+res);
                if (res.data == "success") {
                    layer.alert("上传成功！", {
                        icon: 6
                    })
                    $('#imgUrl').val(res.fileUrl);
                } else {
                    layer.alert("服务出错，请联系管理员！", {
                        icon: 6
                    })
                }

            },
            error: function () {
                layer.alert("上传失败，请联系管理员！", {
                    icon: 6
                })
            }
        });

    });


</script>

</body>

</html>
